#include "HeadFiles.h"

StartWindow::StartWindow()
{
	Init();
}

StartWindow::~StartWindow()
{
	if (node)
		delete node;
	if (pos)
		delete pos;
}

void StartWindow::Show()
{
	for (int i = 0; i < 3; i++)
	{
		if (i == select)
			CBuffer::Instance()->CN_Write(28, 28+i, select_arr[i], Fyellow, Bdark_white);
		else
			CBuffer::Instance()->CN_Write(28, 28+i, select_arr[i], Fdark_red, Bdark_white);
	}
}

void StartWindow::Update()
{
	//std::cout << "void StartWindow::Update()" << std::endl;
	if (KeyBoardInPut::Instance()->KeyDown('W'))
	{
		if (select > 0)
			select--;
	}
	else if (KeyBoardInPut::Instance()->KeyDown('S'))
	{
		if (select < 2)
			select++;
	}
	else if (KeyBoardInPut::Instance()->KeyDown(VK_SPACE))
	{
		if (select == 0)
		{
			to_game = true;
		}
		else if (select == 1)
		{
			pos = new COORD;
			node = new PlayerRole_Inf;
			FileOperation::Instance()->ReadArchivedFile(node, *pos);
			PlayerRole::Instance()->Init(node, *pos);
			to_game = true;
		}
		else
		{
			exit(0);
		}
	}
	if (to_game)
	{
		WindowControl::Instance()->ChangeWindow(Village_Window);
	}
}

void StartWindow::Init()
{
	select = 0;
	to_game = false;
	pos = nullptr;
	node = nullptr;
}
